import {
	mapState
} from 'vuex'
import {
	uniModal,
	uniToast
} from '@/utils/uniPromise.js'
import {
	pageShare
} from "../../../mixins/pageShare.js";
export default {
	mixins: [pageShare],
	data() {
		return {
			strings: '', //富文本
			imgList: [], //图片集合
			dataForm: {},
			shareParams: {},
		};
	},
	computed: {
		...mapState(['vuex_user'])
	},

	created() {
		// this.dataList = JSON.parse(JSON.stringify(this.data))
		this.dataForm = this.data
	},

	methods: {
		// 放大图片
		onPreImg(current){
			wx.previewImage({
			  current:this.dataForm.imgList[current], // 当前显示图片的http链接
			  urls: this.dataForm.imgList // 需要预览的图片http链接列表
			})
		},

		// 复制内容
		onCopyContent(data) {
			wx.setClipboardData({
				data,
				success(res) {
					wx.getClipboardData({
						success(res) {},
						fail(res) {
							wx.showToast({
								title: '复制失败',
								icon: 'none'
							})
						}
					})
				}
			})

		},

		onShare(){
			this.$emit('onShare')
		},
		
		// 手机存入通信录
		addPhone(item) {
			if (!item) {
				return
			}
			this.$login('addPhone').then(() => {
				let {
					email,
					address,
					company,
					duties,
					logo,
					name,
					phone,
					weixin
				} = item
				wx.addPhoneContact({
					firstName: name,
					mobilePhoneNumber: phone,
					weChatNumber: weixin,
					organization: company,
					title: duties,
					workPhoneNumber: phone,
					email: email,
					homeAddressStreet: address
				})

			})
		},
		// 刷新
		refresh() {
			this.$emit('refreshPage')
		},
		// 点击收藏
		collection() {
			this.$login('refresh').then(() => {
				if (this.card_id && this.card_id !== this.vuex_user.card_id) { // 自己不能收藏自己
					let text = '是否取消收藏';
					let colect = false;
					let {
						is_follow,
						my_collection,
					} = this.dataForm
					if (is_follow == '0') {
						text = '是否收藏'
						colect = true
					}
					uniModal({
						content: text
					}).then(() => {

						this.$resPost('SetCallingCardCollection', {
							type: colect ? 1 : 2,
							calling_card_id: this.card_id ? this.card_id : this.vuex_user
								.card_id
						}).then(res => {
							uniToast('操作成功')
							if (colect) {
								is_follow = '1'
								my_collection += 1

							} else {
								is_follow = '0'
								my_collection -= 1
							}
							this.$set(this.dataForm, 'is_follow', is_follow)
							this.$set(this.dataForm, 'my_collection', my_collection)
						})
					})
				}
			})
		},
	}
}
